#include "comm.hpp"
#include <unistd.h>
using namespace std;

int main()
{
    key_t k = getKey();
    printf("K: 0x%x\n",k);
    int shmid = createShm(k);//创建共享内存
    printf("shmid: %d\n",shmid);

      
    char* start = (char*)attachShm(shmid);//进行链接
    printf("server关联成功 %p\n",start);

    //进行通信 /server读取
    int n = 20;
    while(n--)
    {
        printf("client say: %s\n",start);
        sleep(1);
    }

    cout << "server去除关联" << endl;
    detachShm(start);//断开链接

    cout << "等待10秒" << endl;
    sleep(10);
    cout << shmid <<" 资源被删除" << endl;
    delShm(shmid);//删除 共享内存
    return 0;
}